<!--  -->
<template>
    <div>

        <van-form @submit="onSubmit">

            <!-- 头 -->
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ nFromdata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号：</span>
                    <span class="titletext">{{ nFromdata.pmInsId }}</span>
                </div>
            </div>

            <section-header :sectionTitle="'基本信息'" />
            <van-field readonly required name="projectID" :value="fromdata.projectID" label="项目编号:" label-width="5em" />
            <van-field readonly required name="projectName" :value="fromdata.projectName" label="项目名称:"
                label-width="5em" />
            <van-field readonly required name="customerId" :value="fromdata.customerId" label="客户编码:"
                label-width="5em" />
            <van-field readonly required name="customerUnitName" :value="fromdata.customerUnitName" label="客户名称:"
                label-width="5em" />
            <van-field readonly required name="city" :value="fromdata.city" label="地市:" label-width="3em" />
            <van-field readonly required name="counties" :value="fromdata.counties" label="县区:" label-width="3em" />
            <van-field readonly required name="competitiveMode" :value="fromdata.competitiveMode" label="项目竞争方式:"
                label-width="7em" />
            <van-field readonly required name="partnerType" :value="fromdata.partnerType" label="合作类型:"
                label-width="5em" />
            <van-field readonly required name="projectServiceContent" :value="fromdata.projectServiceContent"
                     label="项目实施类型:" label-width="7em" />
            <van-field readonly autosize type="textarea" rows="1" name="projectDescription"
                :value="fromdata.projectDescription" label="项目描述:" label-width="5em" />


            <section-header :sectionTitle="'招应标信息'" />
            <van-field readonly name="bidNoticeUrl" :value="fromdata.bidNoticeUrl" label="招标公告链接:" label-width="7em" />
            <van-field readonly name="bidDate" :value="fromdata.bidDate" label="招标公告日期:" label-width="7em" />
            <van-field readonly required label="招标文件:" label-width="5em" />
            <div v-for="(fileitem) in fromdata.bidFile" :key="fileitem.id" style="margin-left:20px">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                </div>
            </div>

            <van-field readonly name="winBidNoticeUrl" :value="fromdata.winBidNoticeUrl" label="中标标公告链接:"
                label-width="8em" />
            <van-field readonly name="winBidDate" :value="fromdata.winBidDate" label="中标日期:" label-width="5em" />
            <van-field readonly label="中标通知书:" label-width="6em" />
            <div v-for="(fileitem) in fromdata.winBidFile" :key="fileitem.id" style="margin-left:20px">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                </div>
            </div>
            <div v-if="aiDataResult&&aiDataResult.resultData">
              <ai-el-table :aiDataResult="aiDataResult"></ai-el-table>
            </div>
            <van-field readonly required name="issueDate" :value="fromdata.issueDate" label="中标通知书下达（签发）日期:"
                label-width="14em" />
            <van-field readonly required name="disclosureDate" :value="fromdata.disclosureDate" label="项目交底日期:"
                label-width="7em" />
            <van-field readonly name="riskValue" :value="fromdata.riskValue" label="风险值:" label-width="4em" />
            <div class="redtext font11" style="margin: 5px 15px 0px 15px;">
                说明：风险值为中标通知书下达（签发）日期与项目交底日期之差，当风险值大于时效目标值，将触发金库审批。
            </div>


            <van-field readonly label="投标文件:" label-width="5em" />
            <div v-for="(fileitem) in fromdata.tenderFile" :key="fileitem.id" style="margin-left:20px">
                <div readonly class="font14 fileLink" style="color:#0F85CF">
                    <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                </div>
            </div>

            <!-- 跳转意见 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#60a9ec; display: inline-block;width:100%;border: 0px solid #60a9ec;border-radius: 15px 0px 0px 15px;
            padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>

            <!-- 流转下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext"
                    style="display: inline-block; width: 100%; border: 0px solid #60a9ec">{{ buttonTitle }}</van-button>
            </div>
        </van-form>


        <!-- 当前办理人 -->
        <section-header v-if="showHistory" :sectionTitle="'当前办理人'" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                    }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <section-header id="opinion" :sectionTitle="'审批意见'" />
        <opinion-item :approveList="approveList" />

    </div>
</template>


<script>

import { mapGetters } from "vuex";
import { Notify, Toast } from "vant";
import { openFileUrl } from "@/store/openFile";
import util from "@/assets/js/public";
import {
  getSZTDZJFormDetail,
  getProjectDisclose,
  getWfOptMags,
  getWfLinkTracks, fileParsingRequestAnalysisFlowQuery,
} from "@/api/dictapi";

import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';
import aiElTable from "@/components/aiElTable/index.vue";


export default {
    data() {
        return {
            fromdata: {},
            nFromdata: {},
            params: this.$route.query,
            todotype: false,
            toRead: false,
            approveList: [],
            showHistory: false,
            historydata: {},


            buttonTitle: '流转下一步',
            canToNext: true,
            aiDataResult:{}
        };
    },

    computed: {

        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),
    },

    //生命周期--创建完成
    created() {
        if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
        if (this.params.todoType == "1") {
            this.todotype = true;
        } else if (this.params.todoType == "2") {
            this.showHistory = true;
        }else if (this.params.todoType == "3") {
            this.toRead = true;
        }

        if (this.params.location == 'dict.start') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持该环节,请至PC端办理';
        }

        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
      aiElTable,
        SectionHeader,
        OpinionItem

    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {

        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push({
                name: "fileview",
                query: {
                    openFileUrl: openFileUrl(value),
                },
            });
        },

        getdetail() {
            Toast.loading({ message: "加载中", forbidClick: false });
            getSZTDZJFormDetail(
                Object.assign(this.params, { userName: this.user.userName })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.nFromdata = result.data.data;
                }

                this.getDecisionMakingByPmInsId(result.data.data.projectInformationId);
            })

            getWfOptMags(Object.assign(this.params), {
                userName: this.user.userName,
            }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                this.approveList = result.data.data.reverse();
            })

            if (this.showHistory) {

                getWfLinkTracks(Object.assign(this.params), {
                    userName: this.user.userName,
                }).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                        Notify(result.message);
                        return;
                    }
                    if (result.data.data) {
                        //数据过滤，并生成新的数组
                        this.historydata = result.data.data.filter(
                            (item) => item.CURRENTSTATE == 10
                        )[0];
                        if (this.historydata) {
                            if (this.historydata.MANAGER) {
                                this.showHistory = true;
                            } else {
                                this.showHistory = false;
                            }
                        } else {
                            this.showHistory = false;
                        }
                    } else {
                        this.showHistory = false;
                    }
                })
            }

        },

        getDecisionMakingByPmInsId(value) {

            getProjectDisclose(
                Object.assign(this.params, { userName: this.user.userName, esopBusinessId: value })
            ).then((result) => {
                this.fromdetal = {};
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.fromdata = result.data.data;
                    if(this.fromdata.winBidFile){
                      Toast.loading({ message: "加载中", forbidClick: false, });
                      fileParsingRequestAnalysisFlowQuery(Object.assign(this.params, { userName: this.user.userName, fileId: this.fromdata.winBidFile[0].id })).then((result) => {
                        Toast.clear();
                        if (!result.data) {
                          Notify(result.message);
                          return;
                        }
                        if (result.data.data) {
                          this.aiDataResult = result.data.data;
                        }
                      });
                    }
                }
            });
        },

        onSubmit() {

            //提交流转
            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = this.fromdata;
            formSendData.id = this.nFromdata.id;
            formSendData.pmInsId = this.nFromdata.pmInsId;
            formSendData.processType = this.params.pmInsType
            formSendData.workItemId = this.params.workItemId;

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };

            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };

            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    'processType': this.params.pmInsType,
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                    "notificationId":this.params.todoType==3?this.params.wfnid:""
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormProject$api$startSubmitProcess',

                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }));
            this.$router.push({
                name: "srqrsubmit"
            });
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
</style>